package com.itheima.controller.sms;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.core.PageInfo;
import com.itheima.core.R;
import com.itheima.pojo.sms.SmsHomeRecommendProduct;
import com.itheima.pojo.sms.SmsHomeRecommendSubject;
import com.itheima.pojo.sms.vo.UpdateVo;
import com.itheima.service.sms.SmsHomeRecommendSubjectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.Subject;
import java.util.List;

@RestController
@RequestMapping("/home/recommendSubject")
@Slf4j
public class SmsHomeRecommendSubjectController {

    @DubboReference
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;

    /**
     * 添加首页推荐专题
     * @param list
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody List<SmsHomeRecommendSubject> list){
        log.info("添加首页推荐专题"+list.toString());

        smsHomeRecommendSubjectService.create(list);
        return R.success("操作成功");
    }

    /**
     * 批量删除推荐专题
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestParam List<Long> ids){
        log.info("批量删除推荐专题"+ids.toString());
        smsHomeRecommendSubjectService.delete(ids);
        return  R.success("操作成功");
    }


    /**
     * 推荐分页查询
     * @param pageNum
     * @param pageSize
     * @param subjectName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public R list(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {
        log.info("分页查询推荐" + pageNum + "..." + pageSize + "..." + subjectName + "..." + recommendStatus);

        PageInfo pageInfo = smsHomeRecommendSubjectService.pageList(pageNum, pageSize, subjectName, recommendStatus);

        return R.success("操作成功",pageInfo);
    }


    /**
     * 批量修改状态
     * @param
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R update(@RequestParam ("ids")List<Long>ids, @RequestParam Integer recommendStatus){
        smsHomeRecommendSubjectService.updateStatus(ids,recommendStatus);
        return R.success("操作成功");
    }


    /**
     * 修改推荐排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public R updateSort(@PathVariable Long id,@RequestParam Integer sort){
        log.info("修改推荐排序"+id+"..."+sort);
        smsHomeRecommendSubjectService.updateSort(id,sort);
        return R.success("操作成功");
    }

}
